package com.agimatec.locators.predicate;

/**
 * User: simon
 * Date: 04.12.2008
 * Time: 17:17:01
 *
 */
public abstract class Predicate implements LocatorPart{

    public Predicate and(Predicate anotherPredicate) {
        return new ComposedLocatorPart(this, anotherPredicate);
    }

    /**
     * Used to combine predicates.
     */
    private class ComposedLocatorPart extends Predicate {
        private LocatorPart p2;
        private LocatorPart p1;

        ComposedLocatorPart(LocatorPart p1, LocatorPart p2) {
            this.p1 = p1;
            this.p2 = p2;
        }


        public String locatorPartString(LocatorStringFactory factory) {
            return p1.locatorPartString(factory)+
                    p2.locatorPartString(factory);
        }
    }
}
